/*
 * @Desc: 菜单管理
 * @Author: feim
 * @return: {Object}
 * @Date: 2022-06-22 19:14:27
*/

export default {
  namespaced: true,
  state: {
    resources: [],
    sublingsRoute: [],
    menu: []
  },
  getters: {
    getResources(state) {
      return state.resources;
    },
    getMenu(state) {
      return state.menu;
    },
    getSublingsRoute(state) {
      return state.sublingsRoute;
    }
  },
  actions: {
    setResources({ commit }, resources) {
      commit('mergeState', { resources });
    },
    setMenu({ commit }, menu) {
      commit('mergeState', { menu });
    },
    setSublingsRoute({ commit }, sublingsRoute) {
      commit('mergeState', { sublingsRoute });
    }
  },
  mutations: {

    /**
     * 通用改变状态的值
     * @param {Object} state        状态
     * @param {Object} mergeObject  需要改变的对象 {key: value}
     */
    mergeState(state, mergeObject) {
      for (const key in mergeObject) {
        state[key] = mergeObject[key];
      }
    }
  }
};
